﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;

public partial class SystemManage_SystemRebuild : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {                        
        }
    }

    #region Web 窗体设计器生成的代码

    override protected void OnInit(EventArgs e)
    {
        isRequestLogin = true;
        RequestLoginPage = "SystemRebuild.aspx";

        RequestCompetences = Competences.BuildCompetencesList(Competences.Administrator);//页面权限

        base.OnInit(e);
    }

    #endregion

    protected void btnOK_Click(object sender, EventArgs e)
    {
        if (tbPassword.Text != "shovesfs")
        {
            Shove._Web.JavaScript.Alert(this.Page, "系统密码错误，请向开发商咨询此密码！");

            return;
        }

        string sql = ReadFile("SystemRebuild");     //从文件 SystemRebuild.txt 中读取出Sql 语句

        if (Shove.Database.MSSQL.ExecuteSQLScript(sql))
        {
            Shove._Web.JavaScript.Alert(this.Page, "系统重建成功！");
        }
        else
        {
            Shove._Web.JavaScript.Alert(this.Page, "系统重建失败！");
        }
    }

    /// <summary>
    /// 读取系统重建的SQL语句
    /// </summary>
    /// <param name="FileName"> 文件名 </param>      
    private string ReadFile(string FileName)
    {
        string file = "";
        string path = "";

        if (String.IsNullOrEmpty(FileName))
        {
            return file;
        }

        path = System.AppDomain.CurrentDomain.BaseDirectory + "UpFile\\" + FileName + ".txt";
              
        using(StreamReader sr = new StreamReader(path,System.Text.Encoding.GetEncoding("gb2312")))
        {
            file = sr.ReadToEnd();
        }

        return file;
    }
}
